#lang racket
(require net/url)

(define (read-all (port (current-input-port)))
  (define (aux)
    (let ([c (read-char port)])
      (cond
        [(eof-object? c) null]
        [else (cons c (aux))])))
  (list->string (aux)))

(define (kdp-get-servers)
  (define raw-data
    (read-all (get-pure-port (string->url "http://digwebinterface.com/?hostnames=www2.mirai.ca&type=&ns=resolver&useresolver=8.8.4.4&nameservers="))))
  (car (string-split
   ((λ(arg) (substring arg 1 (string-length arg)))
   (car (regexp-match "'.................mirai.ca" raw-data))) "."))
  '("54.248.223.122"))

(define (tcpping ip)
  (define sttime (current-milliseconds))
  (define-values (in out) (tcp-connect ip 443))
  (- (current-milliseconds) sttime))

;(kdp-get-servers)
(provide kdp-get-servers tcpping)